package com.hengtiansoft.lfy.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hengtiansoft.lfy.R;
import com.hengtiansoft.lfy.utils.Kdxf_TTSPlayer;

/**
 * 自定义对话框
 */
public class FirstSoundDialog extends Dialog {

    public FirstSoundDialog(Context context) {
        super(context);
    }

    public FirstSoundDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        private Context context;
        private View contentView;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setContentView(View v) {
            this.contentView = v;
            return this;
        }

        public FirstSoundDialog create() {

            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // instantiate the dialog with the custom Theme
            final FirstSoundDialog dialog = new FirstSoundDialog(context, R.style.myDialogTheme);
            View v = inflater.inflate(R.layout.dialog_first_sound_layout, null);

            RelativeLayout layout_close = (RelativeLayout) v.findViewById(R.id.layout_close);
            layout_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            RelativeLayout layout_one = (RelativeLayout) v.findViewById(R.id.layout_one);
            final TextView tv_content_english1 = (TextView) v.findViewById(R.id.tv_content_english1);
            layout_one.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   // Kdxf_TTSPlayer.getInstense().TTSPlay(tv_content_english1.getText().toString(), "ench", "");
                    Kdxf_TTSPlayer.getInstense().TTSPlayOpu_assets("1.mp3",context);
                }
            });

            RelativeLayout layout_two = (RelativeLayout) v.findViewById(R.id.layout_two);
            final TextView tv_content_english2 = (TextView) v.findViewById(R.id.tv_content_english2);
            layout_two.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   // Kdxf_TTSPlayer.getInstense().TTSPlay(tv_content_english2.getText().toString(), "ench", "");
                    Kdxf_TTSPlayer.getInstense().TTSPlayOpu_assets("2.mp3",context);
                }
            });

            ImageView iv_sound = (ImageView) v.findViewById(R.id.iv_sound);
            iv_sound.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  //  Kdxf_TTSPlayer.getInstense().TTSPlay(tv_content_english1.getText().toString() + "     " + tv_content_english2.getText().toString(), "ench", "");
                    Kdxf_TTSPlayer.getInstense().TTSPlayOpu_assets("3.mp3",context);
                }
            });

            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(v);
            dialog.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                   // Kdxf_TTSPlayer.getInstense().stopTTs();
                    Kdxf_TTSPlayer.getInstense().stop();
                }
            });
            return dialog;
        }
    }
}